package com.liruan.rest.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.liruan.rest.exception.BusinessException;
import com.liruan.rest.service.result.ResultCode;

/**
 * 统一处理DAO层操作返回的异常
 *
 */
@Aspect
@Component
public class DAOInterceptor
{
	private static final Logger LOGGER = LoggerFactory.getLogger(DAOInterceptor.class);

	@Pointcut("execution(* com.liruan.rest.dao..*(..))")
	public void daoMethodPointcut()
	{
	}

	@Around("daoMethodPointcut()")
	public Object Interceptor(ProceedingJoinPoint pjp)
	{
		try
		{
			return pjp.proceed();
		}
		catch (Throwable e)
		{
			throw new BusinessException(e, ResultCode.DB_ACESSS_FAIL);
		}
	}
}
